package com.bwie.bargain.controller;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.bwie.bargain.feign.GoodsFeign;
import com.bwie.bargain.vo.BargainVo;
import com.bwie.bargain.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.bargain.entity.BargainEntity;
import com.bwie.bargain.service.BargainService;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.R;



/**
 * 
 *
 * @author ShuangzhiZhao
 * @email 466505908@qq.com
 * @date 2022-03-07 19:58:55
 */
@RestController
@RequestMapping("bargain/bargain")
public class BargainController {
    @Autowired
    private BargainService bargainService;
    @Autowired
    private GoodsFeign goodsFeign;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bargainService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 拼团列表
     */
    @RequestMapping("/ptlist")
    public R ptlist(){
        List<BargainVo> page=bargainService.mslist();

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{bid}")
    public R info(@PathVariable("bid") Long bid){
		BargainEntity bargain = bargainService.getById(bid);
        GoodsVo info = goodsFeign.info2(bargain.getGoodsId());
        return R.ok().setData(bargain).put("bargain", bargain).put("goods",info);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BargainEntity bargain){
		bargainService.save(bargain);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BargainEntity bargain){
		boolean b=bargainService.updateById(bargain);

        return R.ok().put("b",b);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] bids){
		bargainService.removeByIds(Arrays.asList(bids));

        return R.ok();
    }

}
